﻿#region COPYRIGHT
//--------------------------------------------------------------------------------
// <copyright file="ToolStripDropDownItem.cs" company="starLiGHT Entertainment Studios">
//    Copyright (c) 2011 
//       Roland Rosenkranz (Glatzemann@email.de)
// </copyright>
// <license>
//   This file is part of starLiGHT.GUI.
//
//   It is released under the Microsoft Public License (Ms-PL).
//
//   You should have received a copy of the Microsoft Public License
//   along with starLiGHT.GUI. If not, see http://sle.codeplex.com/license.
//    
//   ADDITIONAL (commercial) LICENSES for starLiGHT.GUI are available on request.
// </license>
// <version>
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev:: 9926                  $:  Revision of last commit *
// * $Author:: unknown            $:  Author of last commit   *
// * $Date:: 2011-05-10 19:07:29 #$:  Date of last commit     *
// ************************************************************
// </version>
//--------------------------------------------------------------------------------
#endregion

namespace starLiGHT.GUI.Widgets
{
    #region Using Statements
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xna.Framework;
    #endregion

    public class ToolStripDropDownItem : ToolStripItem
    {
        #region Private Members
        private ToolStripItemCollection dropDownItems;
        #endregion

        #region Constructors
        public ToolStripDropDownItem()
        {
            this.Init();
        }

        #endregion

        public ToolStripItemCollection DropDownItems
        {
            get
            {
                if (this.dropDownItems == null)
                {
                    this.dropDownItems = new ToolStripItemCollection(this.ToolStrip);
                    this.dropDownItems.ItemAdded += new EventHandler(this.dropDownItems_ItemAdded);
                }

                return this.dropDownItems;
            }
        }

        public override void Draw(GameTime gameTime, IGuiRenderer renderer, ToolStrip toolStrip, ref Microsoft.Xna.Framework.Vector2 topLeft)
        {
            throw new NotImplementedException();
        }

        public override RectangleF GetHitTestRectangle()
        {
            RectangleF hitRect = new RectangleF(Offset, Size);

            return hitRect;
        }

        public override void OnClick(object sender, EventArgs e)
        {
            foreach (ToolStripItem tsi in this.DropDownItems)
            {
                if (tsi.GetHitTestRectangle().Contains(ToolStrip.Manager.PointerPosition))
                {
                    tsi.OnClick(sender, e);
                }
            }

            base.OnClick(sender, e);
        }

        private void Init()
        {
        }

        private void dropDownItems_ItemAdded(object sender, EventArgs e)
        {
            Vector2 offset = Offset + new Vector2(0f, ToolStrip.Manager.DefaultFont.LineSpacing);
            foreach (ToolStripDropDownItem tsi in this.DropDownItems)
            {
                tsi.Offset = offset;
                offset += new Vector2(0f, tsi.Size.Y);
            }
        }
    }
}
